#include <stdio.h>
#include <linux/types.h>
#include <linux/signal.h>
#include "Syscall.h"
#include "System.h"

/// <summary>
/// The GetProcessID function
/// returns the process ID of
/// the current process.
/// </summary>
PID GetProcessID(void)
{
	PID pid = -1;
	if ((pid = Syscall0(__NR_getpid)) < 0)
		return -1;
	return pid;
}

/// <summary>
/// The GetParentProcessID
/// function returns the process ID
/// of the parent of the current process.
/// </summary>
PID GetParentProcessID(void)
{
	PID pid = -1;
	if ((pid = Syscall0(__NR_getppid)) < 0)
		return -1;
	return pid;
}

/// <summary>
/// The GetProcessGroupId function
/// returns the process group ID of
/// the process specified by pid. If pid
/// is zero, the process ID of the
/// current process is used.
/// </summary>
PID GetProcessGroupID(PID pid)
{
	PID pgid = -1;
	if ((pgid = Syscall1(__NR_getpgrp, (int)pid)) < 0)
		return -1;
	return pgid;
}

/// <summary>
/// The CreateProcess function
/// returns the process ID of
/// the current process.
/// </summary>
PID CreateProcess()
{
	return -1;
}

/// <summary>
/// The GetProcessID function
/// returns the process ID of
/// the current process.
/// </summary>
PID ProcessWait(void)
{
	PID pid = -1;
	if ((pid = Syscall0(__NR_getpid)) < 0)
		return -1;
	return pid;
}

/// <summary>
/// The CloseProcess function
/// returns the process ID of
/// the current process.
/// </summary>
int CloseProcess(PID pid)
{
	if (pid <= 1)
		return -1;
	if (Syscall2(__NR_kill, (int)pid, SIGKILL) < 0)
		return -1;
	return 0;
}
